home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 14.2 KB | 354 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: SLStrRep.h
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef SLSTRREP_H
- #define SLSTRREP_H
-
- #ifndef SLLOCALE_H
- #include "SLLocale.h"
- #endif
-
- // Export or Import functions for CFM-68K [sfu]
-
- #if defined(FW_ODFLIB_IMPORT)
- #pragma import on
- #elif defined(FW_ODFLIB)
- #pragma export on
- #endif
-
- FW_EXTERN_C_BEGIN
-
- // NOTES
- //
- // StringReps are reference counted, so they are always heap allocated.
- // This allows us to make them be an opaque data structure.
- // Since they are opaque, ALL access is through accessor functions.
- // This means that storage allocation is under complete control
- // of the SLStrRep subsystem.
-
- //========================================================================================
- // Forward Declarations
- //========================================================================================
-
- struct ODIText;
-
- void FW_PrivInitStringData();
- FW_Locale FW_PrivGetDefaultLocale();
-
- //========================================================================================
- // STRUCT FW_SPrivStringRep
- //========================================================================================
-
- struct FW_SPrivStringRep;
- // An opaque data structure!
-
- typedef FW_SPrivStringRep* FW_HString;
- // A handle to a string. The preferred way to reference a PrivStringRep
-
- //========================================================================================
- // FW_SPrivStringRep Member Functions
- //========================================================================================
-
- FW_HString FW_PrivString_AcquireEmptyString();
- // Returns a rep for an empty (roman, english) string.
- // The rep is shared by all empty strings.
-
- FW_HString FW_PrivString_AcquireEmptyStringWithLocale(FW_Locale locale, FW_PlatformError* error);
- // Returns a rep for an empty string from specified locale.
- // This always creates a new rep.
-
- void FW_PrivString_Acquire(FW_HString self);
- // Increments the reference count
-
- void FW_PrivString_Release(FW_HString self);
- // Decrements the reference count.
- // If the reference count is zero, the client will probably want
- // to immediately call FW_PrivString_Delete, though the call
- // may be deferred if the client wants to reuse the structure.
-
- FW_HString FW_PrivString_LockString(FW_HString self, FW_PlatformError* error);
- // Locks the string (if not already locked) and returns the locked rep.
-
- FW_HString FW_PrivString_NewRepWithStaticBuffer(unsigned char* buffer,
- FW_ByteCount bufferLen);
- // Allocate a new rep that uses the given static buffer
- // This function may fail due to insufficient memory, if so NULL is returned.
- // No error code is returned because the intention is that this function
- // is to only be called from a constructor's initializer list
-
- void FW_PrivString_ReleaseStaticBuffer(FW_HString self, FW_PlatformError* error);
- // Release use of a static buffer.
-
- void FW_PrivString_Retrieve(FW_HString self,
- char* destination,
- FW_ByteCount numberChars,
- FW_BytePosition position);
- // Retrieve a range of bytes from the string, placing them in destination.
-
- FW_HString FW_PrivString_Delete(FW_HString self,
- FW_ByteCount numberBytes,
- FW_BytePosition position,
- FW_PlatformError* error);
- // Delete a range of bytes from the string.
-
- FW_ByteCount FW_PrivString_GetByteLength(FW_HString self);
- // Returns the number of bytes holding character codes (not the number of characters!)
-
- FW_ByteCount FW_PrivString_GetCapacity(FW_HString self);
- // Returns the current capacity for bytes, which may be expanded using SetCapacity
-
- FW_CharacterCount FW_PrivString_GetCharacterLength(FW_HString self, FW_PlatformError* error);
- // Returns the number of characters in the string.
- // For some character sets this may be relatively expensive!
- // For efficiency, if GetByteLength will suffice, use it.
-
- FW_HString FW_PrivString_SetCapacity(FW_HString self,
- FW_ByteCount newCapacity,
- FW_PlatformError* error);
- // Sets the new capacity, which is the largest number of bytes
- // that may be used for holding character codes.
-
- ODIText* FW_PrivString_RevealODIText(FW_HString self);
- // Reveals the ODIText data structure.
- // This function is provided to make it efficient to pass
- // strings to OpenDoc APIs that are defined with "in ODIText"
- // parameters. Clients must not modify the revealed ODIText
- // data structure, or all hell may break loose. ;>
-
- const char* FW_PrivString_RevealBuffer(FW_HString self);
- // Reveals the character buffer.
- // This function is provided to make it efficient to directly
- // process the bytes of storage. Clients must not modify the revealed buffer,
- // or all hell may break loose. ;>
- // NOTE: the buffer is probably NOT nul-terminated!!
-
- FW_Locale* FW_PrivString_RevealLocale(FW_HString self);
- // Reveals the locale.
- // Used when creating a TextReader.
-
- void FW_PrivString_GetLocale(FW_HString self, FW_Locale* locale);
- // Return this string's locale.
-
- FW_HString FW_PrivString_Truncate(FW_HString self,
- FW_BytePosition bytePosition,
- FW_PlatformError* error);
- // Removes the given run of bytes from the current contents.
- // It is the client's responsiblity to insure that no double byte characters
- // are broken!
-
- //----------------------------------------------------------------------------------------
- // Insert Functions
- //----------------------------------------------------------------------------------------
-
- FW_HString FW_PrivString_InsertBytes(FW_HString self,
- const char* bytes,
- FW_ByteCount numberBytes,
- FW_BytePosition position,
- FW_PlatformError* error);
- // Inserts the given bytes at the given byte position.
- // It is the client's responsiblity to insure that bytePosition does not
- // split a double byte character! Hint: bytePosition should have been determined
- // using a function known to return valid character offsets.
-
- FW_HString FW_PrivString_InsertODIText(FW_HString self,
- ODIText* text,
- FW_BytePosition position,
- FW_PlatformError* error);
- // Inserts the given text at the given byte position.
- // It is the client's responsiblity to insure that bytePosition does not
- // split a double byte character!
-
- FW_HString FW_PrivString_InsertStringRep(FW_HString self,
- FW_HString other,
- FW_BytePosition position,
- FW_PlatformError* error);
- // Inserts the given text at the given byte position.
- // It is the client's responsiblity to insure that bytePosition does not
- // split a double byte character!
-
- //----------------------------------------------------------------------------------------
- // Replace Functions
- //----------------------------------------------------------------------------------------
-
- FW_HString FW_PrivString_ReplaceAllStringRep(FW_HString self,
- FW_HString text,
- FW_PlatformError* error);
- // Replaces the current contents with the given text.
-
- FW_HString FW_PrivString_ReplaceAllODIText(FW_HString self,
- ODIText* text,
- FW_PlatformError* error);
- // Replaces the current contents with the given text.
-
- FW_HString FW_PrivString_ReplaceAllBytes(FW_HString self,
- const char* bytes,
- FW_ByteCount numberBytes,
- FW_PlatformError* error);
- // Replaces the current contents with the given text.
-
- //----------------------------------------------------------------------------------------
- // Append Functions
- //----------------------------------------------------------------------------------------
-
- FW_HString FW_PrivString_AppendODIText(FW_HString self,
- ODIText* text,
- FW_PlatformError* error);
- // Appends the given text onto the end of the current contents.
-
- FW_HString FW_PrivString_AppendStringRep(FW_HString self,
- FW_HString text,
- FW_PlatformError* error);
- // Appends the given text onto the end of the current contents.
-
- FW_HString FW_PrivString_AppendBytes(FW_HString self,
- const char* bytes,
- FW_ByteCount numberBytes,
- FW_PlatformError* error);
- // Appends the given bytes onto the end of the current contents.
-
- //----------------------------------------------------------------------------------------
- // Prepend Functions
- //----------------------------------------------------------------------------------------
-
- FW_HString FW_PrivString_PrependODIText(FW_HString self,
- ODIText* text,
- FW_PlatformError* error);
- // Prepends the given text onto the beginning of the current contents.
-
- FW_HString FW_PrivString_PrependStringRep(FW_HString self,
- FW_HString text,
- FW_PlatformError* error);
- // Prepends the given text onto the beginning of the current contents.
-
- FW_HString FW_PrivString_PrependBytes(FW_HString self,
- const char* bytes,
- FW_ByteCount numberBytes,
- FW_PlatformError* error);
- // Prepends the given bytes onto the beginning of the current contents.
-
- //----------------------------------------------------------------------------------------
- // Export Functions
- //----------------------------------------------------------------------------------------
-
- void FW_PrivString_ExportCString(FW_HString self, char* buffer);
- // Copy contents of this string to external buffer as a NUL-terminated C string.
-
- void FW_PrivString_ExportPascalString(FW_HString self, FW_PascalChar* buffer);
- // Copy contents of this string to external 'Pascal' buffer.
-
- //----------------------------------------------------------------------------------------
- // Monocasing Functions
- //----------------------------------------------------------------------------------------
-
- FW_HString FW_PrivString_ToUpper(FW_HString self, FW_PlatformError* error);
- // Convert all lowercase characters to uppercase.
-
- FW_HString FW_PrivString_ToLower(FW_HString self, FW_PlatformError* error);
- // Convert all uppercase characters to lowercase.
-
- //----------------------------------------------------------------------------------------
- // Searching and Substitution Functions
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_PrivString_FindCharacter(FW_HString self,
- FW_LChar character,
- FW_ByteCount *foundPosition,
- FW_ByteCount startPosition,
- FW_FindDirection direction);
- // Find the first occurence of character, starting the search at startPosition.
- // Return false if the character is not found.
-
- FW_Boolean FW_PrivString_FindSubString(FW_HString self,
- FW_HString subString,
- FW_ByteCount *foundPosition,
- FW_ByteCount startPosition);
- // Find the first occurence of substring, starting the search at startPosition.
- // Return false if the substring is not found.
-
- FW_HString FW_PrivString_Substitute(FW_HString self,
- FW_HString searchString,
- FW_HString substitutionString,
- FW_Boolean* wasReplaced,
- FW_PlatformError* error);
- // Find the first occurence of substring, starting the search at startPosition.
- // If the substring is found, replace it with the substitution string.
- // Set wasReplace to false if the substring was not found.
-
- FW_StringCompareResult FW_PrivString_Compare(FW_HString string1, FW_HString string2);
- // Compare the two strings (taking into account locality of the strings).
-
- //----------------------------------------------------------------------------------------
- // Number Conversion Functions
- //----------------------------------------------------------------------------------------
-
- FW_HString FW_PrivString_SignedIntegerToDecimalString(FW_HString self,
- long integer,
- FW_PlatformError* error);
- // Given a signed long integer, create a string with it's decimal representation
-
- FW_HString FW_PrivString_UnsignedIntegerToDecimalString(FW_HString self,
- unsigned long integer,
- FW_PlatformError* error);
- // Given a unsigned long integer, create a string with it's decimal representation
-
- FW_HString FW_PrivString_UnsignedIntegerToHexadecimalString(FW_HString self,
- unsigned long integer,
- FW_PlatformError* error);
- // Given a unsigned long integer, create a string with it's hexadecimal representation.
- // The uppercase letters A-F are used.
-
- long FW_PrivString_DecimalStringToSignedInteger(FW_HString self);
- // Given a string, return the integer.
- // Assumes the string contains a valid decimal representation.
- // The string is parsed to the first non-decimal character (including '-').
- // Zero is returned if the first character is not a decimal character.
- // No error is returned under any condition.
-
- unsigned long FW_PrivString_DecimalStringToUnsignedInteger(FW_HString self);
- // Given a string, return the unsigned integer.
- // Assumes the string contains a valid decimal representation.
- // The string is parsed to the first non-decimal character (not including '-').
- // Zero is returned if the first character is not a decimal character.
- // No error is returned under any condition.
-
- unsigned long FW_PrivString_HexadecimalStringToUnsignedInteger(FW_HString self);
- // Given a string, return the unsigned integer.
- // Assumes the string contains a valid hexadecimal representation.
- // The string is parsed to the first non-hexadecimal character
- // (including a-f, A-F, not including '-').
- // Zero is returned if the first character is not a decimal character.
- // No error is returned under any condition.
-
- FW_HString FW_PrivString_DoubleToString(FW_HString self,
- double value,
- short fractionalDigits,
- FW_PlatformError* error);
- // Given a floating point value, create a string with it's decimal representation
- // fractionalDigits is the number of digits to be shown after the decimal point.
- // All digits to the left of the decimal point are shown (sci notation is never used).
-
- double FW_PrivString_StringToDouble(FW_HString self);
- // Given a string, return the double.
- // Assumes the string contains a valid floating point representation.
- // Zero is returned if the first character is not a decimal character (include '-').
- // No error is returned under any condition.
-
- FW_EXTERN_C_END
-
- // For CFM-68K [sfu]
-
- #if defined(FW_ODFLIB_IMPORT)
- #pragma import off
- #elif defined(FW_ODFLIB)
- #pragma export off
- #endif
-
- #endif
-
-